#include <iostream>
#include <fstream>
#include <string>
#include "bundle.h"

using namespace std;

// g++ compress.cc bundle.cpp -o compress -std=c++11 -lpthread
// compress 原始文件名 压缩后文件名
int main(int argc, char *argv[])
{
    if(argc != 3)
    {
        cout << "参数错误" << endl;
        cout << "使用格式应为：compress 原始文件名 压缩后文件名" << endl;
        return -1;
    }

    string ori_file = argv[1];
    string com_file = argv[2];

    ifstream ifs;
    ifs.open(ori_file.c_str(), ios::binary);
    ifs.seekg(0, ifs.end);
    size_t fsize = ifs.tellg();
    ifs.seekg(0, ifs.beg);

    string ori;
    ori.resize(fsize);
    ifs.read(&ori[0], fsize);

    string com = bundle::pack(bundle::LZIP, ori);

    ofstream ofs;
    ofs.open(com_file, ios::binary);
    ofs.write(&com[0], com.size());

    ifs.close();
    ofs.close();

    return 0;
}